package com.ruoyi.project.simple.controller;

import java.util.List;

import com.ruoyi.project.simple.domain.vo.SplOrderDetailVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.simple.domain.SplOrderDetail;
import com.ruoyi.project.simple.service.ISplOrderDetailService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 样品订单明细Controller
 * 
 * @author zhujj
 * @date 2020-01-09
 */
@RestController
@RequestMapping("/simple/orderDetail")
public class SplOrderDetailController extends BaseController
{
    @Autowired
    private ISplOrderDetailService splOrderDetailService;

    /**
     * 查询样品订单明细列表
     */
    @PreAuthorize("@ss.hasPermi('simple:orderDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(SplOrderDetail splOrderDetail)
    {
        startPage();
        List<SplOrderDetailVO> list = splOrderDetailService.selectSplOrderDetailList(splOrderDetail);
        return getDataTable(list);
    }

    /**
     * 导出样品订单明细列表
     */
    @PreAuthorize("@ss.hasPermi('simple:orderDetail:export')")
    @Log(title = "样品订单明细", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SplOrderDetail splOrderDetail)
    {
        List<SplOrderDetailVO> list = splOrderDetailService.selectSplOrderDetailList(splOrderDetail);
        ExcelUtil<SplOrderDetailVO> util = new ExcelUtil<SplOrderDetailVO>(SplOrderDetailVO.class);
        return util.exportExcel(list, "orderDetail");
    }

    /**
     * 获取样品订单明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('simple:orderDetail:query')")
    @GetMapping(value = "/{orderDetailId}")
    public AjaxResult getInfo(@PathVariable("orderDetailId") String orderDetailId)
    {
        return AjaxResult.success(splOrderDetailService.selectSplOrderDetailById(orderDetailId));
    }

    /**
     * 新增样品订单明细
     */
    @PreAuthorize("@ss.hasPermi('simple:orderDetail:add')")
    @Log(title = "样品订单明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SplOrderDetail splOrderDetail)
    {
        return toAjax(splOrderDetailService.insertSplOrderDetail(splOrderDetail));
    }

    /**
     * 修改样品订单明细
     */
    @PreAuthorize("@ss.hasPermi('simple:orderDetail:edit')")
    @Log(title = "样品订单明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SplOrderDetailVO splOrderDetail)
    {
        return toAjax(splOrderDetailService.updateSplOrderDetail(splOrderDetail));
    }

    /**
     * 删除样品订单明细
     */
    @PreAuthorize("@ss.hasPermi('simple:orderDetail:remove')")
    @Log(title = "样品订单明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderDetailIds}")
    public AjaxResult remove(@PathVariable String[] orderDetailIds)
    {
        return toAjax(splOrderDetailService.deleteSplOrderDetailByIds(orderDetailIds));
    }
}
